package com.appkubes.fintech.admin.application.mall.impl;

import com.appkubes.fintech.admin.application.mall.MallService;
import com.appkubes.fintech.admin.util.MyOkHttpUtil;
import com.appkubes.fintech.core.po.FintechUserBaseInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: Rongjie
 * @Date: 2020/2/28
 * @Description:
 */
@Service
@Slf4j
public class MallServiceImpl implements MallService {

    @Value("${mall.data.adminHostUrl}")
    String hostUrl;

    String mallOrderRentStatusUpdate = "/order/rent/status/update";
    String mallUserUpdate = "/user/update";

    @Override
    public String notifyOrderEnsure(String userKey, String orderKey, Integer rentStatus) {
        log.info("notifyOrderEnsure: userKey:{}, orderKey:{}", userKey, orderKey);
        Map<String, String> params = new HashMap<>();
        params.put("userKey", userKey);
        params.put("orderKey", orderKey);
        params.put("rentStatus", rentStatus.toString());
        String result = MyOkHttpUtil.postForBody(hostUrl + mallOrderRentStatusUpdate, params);
        return result;
    }

    @Override
    public String notifyUserApproval(FintechUserBaseInfo baseInfo) {
        log.info("notifyUserApproval: {}", baseInfo.getUserKey());
        //将基础信息同步回商城系统，以方便商城系统查询
        Map<String, String> params = new HashMap<>();
        params.put("userKey", baseInfo.getUserKey());
        params.put("name", baseInfo.getRealName());
        params.put("idCard", baseInfo.getIdentityNum());
        String result = MyOkHttpUtil.postForBody(hostUrl + mallUserUpdate, params);
        return result;
    }
}
